package com.system.service.impl;

import com.system.mapper.ItemMapper;
import com.system.pojo.Item;
import com.system.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("buyerService")
public class ItemServiceImpl implements ItemService {

    @Autowired
    ItemMapper itemMapper;

    @Override
    public List<Item> selectItem(Item item) {
        return itemMapper.selectItem();
    }

    @Override
    public List<Item> selectItemByPage(Item item, int page, int limit) {
        int starRow = (page-1)*limit+1;
        int endRow = page*limit;
        String itemCode = null;
        if (item.getItemCode() != null && item.getItemCode() != "") {
            itemCode = "%" + item.getItemCode() + "%";
        } else {
            itemCode = item.getItemCode();
        }
        return itemMapper.selectItemByPage(itemCode,starRow,endRow);
    }

    @Override
    public void delItem(String id) {
        try {
            itemMapper.delItem(id);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void insertItem(Item item) {
        itemMapper.insertItem(item);
    }

    @Override
    public void updateItem(Item item) {
        itemMapper.updateItem(item);
    }


}
